package net.tolkv.tdd;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.UUID;

import com.tolkv.tdd.ws.AmazonItem;
import com.tolkv.tdd.ws.AmazonStoreWebService;

public class AmazonStoreWebServiceWrapper implements IStoreService {
	private AmazonStoreWebService amazonService;
	private String sessionId;

	public AmazonStoreWebServiceWrapper(AmazonStoreWebService amazonService) {
		this.amazonService = amazonService;
	}

	public void addItem(Item item) {

	}

	public Collection<Item> getItems() {
		List<AmazonItem> items = amazonService.getItems(getSession());
		List<Item> ret = new ArrayList<Item>(items.size());
		for (AmazonItem aitem : items) {
			ret.add(new AmazonItemAdapter(aitem));
		}
		return ret;
	}

	private String getSession() {
		if(sessionId==null)
			return amazonService
				.getSessionId();
		else
			return sessionId;
	}

	public void sellItem(Item a) {
		amazonService.sell(getSession(),((AmazonItemAdapter)a).getAmazonId(), 1);
	}

	public Item findItem(Item a) {
		return null;
	}

	public Item findItem(UUID id) {
		return null;
	}

	public int getTotalItemsAmount() {
		return 0;
	}
	public int getProfit() {

		return 0;
	}

}
